<template>
  <div class="dashboard">
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <template #header>
            <div class="card-header">
              <span>总库存</span>
              <el-icon><Goods /></el-icon>
            </div>
          </template>
          <div class="card-content">
            <div class="number">1,234</div>
            <div class="text">件商品</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <template #header>
            <div class="card-header">
              <span>本月采购</span>
              <el-icon><ShoppingCart /></el-icon>
            </div>
          </template>
          <div class="card-content">
            <div class="number">56</div>
            <div class="text">个订单</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <template #header>
            <div class="card-header">
              <span>本月销售</span>
              <el-icon><Money /></el-icon>
            </div>
          </template>
          <div class="card-content">
            <div class="number">89</div>
            <div class="text">个订单</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="data-card">
          <template #header>
            <div class="card-header">
              <span>供应商</span>
              <el-icon><House /></el-icon>
            </div>
          </template>
          <div class="card-content">
            <div class="number">23</div>
            <div class="text">家</div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="20" class="mt-20">
      <el-col :span="12">
        <el-card shadow="hover">
          <template #header>
            <div class="card-header">
              <span>库存预警</span>
            </div>
          </template>
          <el-table :data="warningData" style="width: 100%">
            <el-table-column prop="name" label="商品名称" />
            <el-table-column prop="stock" label="当前库存" />
            <el-table-column prop="warning" label="预警值" />
            <el-table-column prop="status" label="状态">
              <template #default="scope">
                <el-tag type="danger">库存不足</el-tag>
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card shadow="hover">
          <template #header>
            <div class="card-header">
              <span>最近采购订单</span>
            </div>
          </template>
          <el-table :data="orderData" style="width: 100%">
            <el-table-column prop="orderNo" label="订单编号" />
            <el-table-column prop="supplier" label="供应商" />
            <el-table-column prop="amount" label="金额" />
            <el-table-column prop="status" label="状态">
              <template #default="scope">
                <el-tag type="success">已完成</el-tag>
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { Goods, ShoppingCart, Money, House } from '@element-plus/icons-vue'

const warningData = ref([
  {
    name: '商品A',
    stock: 10,
    warning: 20,
    status: 'danger'
  },
  {
    name: '商品B',
    stock: 5,
    warning: 15,
    status: 'danger'
  },
  {
    name: '商品C',
    stock: 8,
    warning: 25,
    status: 'danger'
  }
])

const orderData = ref([
  {
    orderNo: 'PO20240317001',
    supplier: '供应商A',
    amount: '￥1,234.56',
    status: 'success'
  },
  {
    orderNo: 'PO20240317002',
    supplier: '供应商B',
    amount: '￥2,345.67',
    status: 'success'
  },
  {
    orderNo: 'PO20240317003',
    supplier: '供应商C',
    amount: '￥3,456.78',
    status: 'success'
  }
])
</script>

<style scoped>
.dashboard {
  /* padding: 20px; */
}

.mt-20 {
  margin-top: 20px;
}

.data-card {
  height: 120px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-content {
  text-align: center;
  padding: 10px 0;
}

.number {
  font-size: 24px;
  font-weight: bold;
  color: #409EFF;
}

.text {
  font-size: 14px;
  color: #909399;
  margin-top: 5px;
}
</style> 